Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

nice_things/utility/readlink.sh

Since 0.3.0 · Source

import "{ readlink }" from nice_things/utility/readlink.sh

Synopsis
readlink [-n] [--] <file>

Configuration

Description
Print value of a symbolic link.

This is a sh implementation of the readlink utility specified in POSIX.

Being an implementation of a CLI utility, this function prints the result to stdout. If you want to assign the result to a variable, consider using the faster read_link function instead.

Note

This is not a pure sh implementation because it depends on the external ls utility to read the target of the symlink. This works consistently because the output of ls is strictly specified in POSIX, but it means this function can be slower than most other functions in the framework.

Options

  • -n: Do not output a trailing line-feed character.
  • --: End of options.

Operands
<file>: Path to a symbolic link.

Stdin

Stdout
The result is printed to stdout, trailed by a line-feed character (unless the -n option was used).

Stderr
log_error.

Exit status

  • 0: Successful completion.
  • 22: <file> is not a symbolic link.
  • 123: Unexpected error.

Abort

Usage examples

readlink /path/to/link